﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace dotFitness.Domain
{
    public sealed class TrainingDay : ScheduleDayBase, IEnumerable<ScheduleExercise>
    {
        private TrainingDay()
            : base()
        {
        }

        internal TrainingDay(int day, string name = null)
            : base(day)
        {
            this.Name = name;
        }

        public ScheduleExercise AddExercise(int exerciseId, int numberOfSets, int minReps, int maxReps)
        {
            if (numberOfSets < 1)
                throw new ArgumentOutOfRangeException("must be greater than zero", "numberOfSets");

            if (minReps < 1)
                throw new ArgumentOutOfRangeException("must be greater than zero", "minReps");

            if (maxReps < 1)
                throw new ArgumentOutOfRangeException("must be greater than zero", "maxReps");

            var scheduledExcercise = new ScheduleExercise(exerciseId, numberOfSets, new RepRange(minReps, maxReps));

            this.Exercises.Add(scheduledExcercise);

            return scheduledExcercise;
        }

        public void RemoveExercise(ScheduleExercise exercise)
        {
            if (null == exercise)
                throw new ArgumentNullException("exercise");

            if (this.Exercises.Contains(exercise) == false)
                throw new ArgumentException("exercise does not belong to schedule", "exercise");

            this.Exercises.Remove(exercise);
        }

        public IEnumerator<ScheduleExercise> GetEnumerator()
        {
            return this.Exercises.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}
